<?
require_once("../config/dbconn.php");require_once("../config/powercls.php");


//奖金发放

$lstperiods=$periods-1;

$sqlp="select * from {$db_prefix}salarym where periods='$periods'";
$rsp=$db->get_one($sqlp);
$jsstate=$rsp['state'];$jsstate1=$rsp['state1'];

if ($jsstate==0){
	die("本期奖金还没有结算.不能发放<br>");
}
//发放了就不能再发放
if ($jsstate==2){
	die("本期奖金已经发放了.不能再次发放<br>");
}
if ($jsstate1==1){
	die("本期奖金结算的时候出现错误。或者正在结算中。不能发放<br>");
}

//开始发放奖金
$sql="select * from {$db_prefix}salarym1 where periods='$periods'";
$result=$db->query($sql);
while($rs=$db->fetch_array($result)){
	if ($rs['isff']==0){
		$hyjjall=$rs['pyjprice']+$rs['cfxfprice']+$rs['lvprice']+$rs['mcprice']+$rs['fhprice'];
		//发放奖金
		$sqljj="update {$db_prefix}users set jjprice=jjprice+'$hyjjall' where id='".$rs['userid']."'";
		$db->query($sqljj);
		$sqlgx="update {$db_prefix}salarym1 set isff=1,fftime='$curtime' where id='".$rs['id']."'";
		$db->query($sqlgx);
		//财务记录
		$e_userid=$rs['userid'];$e_price=$hyjjall;$e_type=11;$e_ptype=3;$e_addtime=$curtime;$e_memo="发放第{$periods}期月奖金";
		hyepricejl($e_userid,$e_price,$e_type,$e_ptype,$e_addtime,$e_memo);
	}
}
$db->free_result($result);


//结算完成以后更新数据
$sqlgx="update {$db_prefix}salarym set state=2,fftime='$curtime' where periods='$periods'";
$db->query($sqlgx);

echo "本期奖已经发放<bR>";

echo "<a href='salary_lst1.php?pageno={$pageno}' style='color:red'>进入奖金列表</a>";
exit();
?>